const app = getApp();
// const {gotoJingdian} = require('../../utils/util')
const utils = require('../../utils/util.js')

Page({

    /**
     * 页面的初始数据
     */
    data: {
        inp:'',
        one:0,
        judge:[],
        currenttab:'0',
        sousuo_imgUrl:'/icon/sousuo.png',
        tuijian:'/icon/tuijian.png',
        jingdian:'/icon/jingdian.png',
        meishi:'/icon/meishi.png',
        jiudian:'/icon/jiudian.png',
        shoucang:'/icon/shoucang.png',
        yishoucang:'/icon/yishoucang.png',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    // 跳转详情页
    gotoDetail:function(e){
        var i = e.currentTarget.dataset.index + 1;
        var index
        // i:点击的卡片的index + 1
        if(i < 10){
            index = '0' + i
        }
        // console.log('2',this.data.list[i-1].recomName)
        wx.navigateTo({
          url: `/pages/rim_detail/rim_detail?index=${index}&info=${this.data.info}&type=${this.data.list[i-1].type}&name=${this.data.list[i-1].recomName}`,
        })
    },

    // 点击按钮变化页面
    showTuijian:function(){
        this.setData({
            one:0,
            info:'tuijian'
        })
        wx.request({
            url: `https://wx.qasdwer.top:2001/rim?info=tuijian&city=${this.data.localCity}`,
            method: 'GET',
            dataType: 'json',
            success: res => {
                this.setData({
                    list:res.data,
                    lunbo4_imgUrl:res.data[0].recomImg,
                    lunbo5_imgUrl:res.data[1].recomImg,
                    lunbo6_imgUrl:res.data[2].recomImg 
                })
            },
            fail: res => {
                console.log('error')
            }
        })
    },
    showJingdian:function(){
        this.setData({
            one:1,
            info:'jingdian'
        })
        wx.request({
            url: `https://wx.qasdwer.top:2001/rim?info=jingdian&city=${this.data.localCity}`,
            method: 'GET',
            dataType: 'json',
            success: res => {
                this.setData({
                    list:res.data,
                    lunbo4_imgUrl:res.data[0].placeImg,
                    lunbo5_imgUrl:res.data[1].placeImg,
                    lunbo6_imgUrl:res.data[2].placeImg 
                })
            },
            fail: res => {
                console.log('error')
            }
        })
    },
    showMeishi:function(){
        this.setData({
            one:2,
            info:'meishi'
        })
        wx.request({
            url: `https://wx.qasdwer.top:2001/rim?info=meishi&city=${this.data.localCity}`,
            method: 'GET',
            dataType: 'json',
            success: res => {
                this.setData({
                    list:res.data,
                    lunbo4_imgUrl:res.data[0].foodImg,
                    lunbo5_imgUrl:res.data[1].foodImg,
                    lunbo6_imgUrl:res.data[2].foodImg 
                })
            },
            fail: res => {
                console.log('error')
            }
        })
    },
    showJiudian:function(){
        this.setData({
            one:3,
            info:'jiudian'
        })
        wx.request({
            url: `https://wx.qasdwer.top:2001/rim?info=jiudian&city=${this.data.localCity}`,
            method: 'GET',
            dataType: 'json',
            success: res => {
                console.log(res.data);
                this.setData({
                    list:res.data,
                    lunbo4_imgUrl:res.data[0].pubImg,
                    lunbo5_imgUrl:res.data[1].pubImg,
                    lunbo6_imgUrl:res.data[2].pubImg 
                })
            },
            fail: res => {
                console.log('error')
            }
        })
    },

    
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        this.showTuijian()

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.setData({
            localCity:getApp().data.localCity
        })
        console.log(this.data.localCity);
        var city = this.data.localCity
        if(this.data.one == 0){
            this.setData({info : 'tuijian'})
        }else if(this.data.one == 1){
            this.setData({info : 'jingdian'})
        }else if(this.data.one == 2){
            this.setData({info : 'meishi'})
        }else{
            this.setData({info : 'jiudian'})
        }
        // 请求周边推荐列表信息
        wx.request({
            url: `https://wx.qasdwer.top:2001/rim?info=${this.data.info}&city=${city}`,
            method: 'GET',
            dataType: 'json',
            success: res => {
                var data = res.data;
                console.log(data)
                this.setData({
                    list:data,
                    lunbo4_imgUrl:data[0].recomImg,
                    lunbo5_imgUrl:data[1].recomImg,
                    lunbo6_imgUrl:data[2].recomImg 
                })
            },
            fail: res => {
                console.log('error')
            }
        })
       
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    //获取输入框的值并且可以回车搜索
    search:function(e){
        this.setData({
            inp:e.detail.value
        }) 
        this.search_rim()
    },
   //跳转搜索页
   search_rim:function(){
    //    console.log(this.data.inp)
       var input=this.data.inp
       this.setData({
           value:''
       })
        wx.navigateTo({
          url: `/pages/search_rim/search_rim?inp=${input}`,
        })
   },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})